package math;
import java.io.Serializable;

public class Vector3f extends Tuple3f implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3063561618554192933L;

	/**
	 * Constructs and initializes a Vector3f to (0,0,0).
	 */

	public Vector3f() {
	}

	/**
	 * Constructs and initializes a Vector3f from the specified xyz coordinates.
	 * 
	 * @param x
	 * @param y
	 * @param z
	 */

	public Vector3f(float x, float y, float z) {
		super(x, y, z);
	}

	/**
	 * Constructs and initializes a Vector3f from the specified Vector3f
	 * 
	 * @param v
	 */

	public Vector3f(Vector3f v) {
		super(v);
	}

	/**
	 * Constructs and initializes a Vector3f from the specified Tuple3f.
	 * 
	 * @param t
	 */

	public Vector3f(Tuple3f t) {
		super(t);
	}

	/**
	 * Constructs and initializes a Vector3f from the array of length 3.
	 * 
	 * @param v
	 */

	public Vector3f(float v[]) {
		super(v);
	}
	
	public Vector3f crossProduct(Vector3f other){
		float x = (this.y*other.z) - (this.z*other.y);
		float y = (this.z*other.x) - (this.x*other.z);
		float z = (this.x*other.y) - (this.y*other.x);
		return new Vector3f(x, y, z);
	}
	
	public float length(){
		float result = this.x*this.x;
		result += this.y*this.y;
		result += this.z*this.z;
		result = (float) Math.sqrt(result);
		return result;
	}
	
	public Vector3f scale(float scalar){
		return new Vector3f(this.x*scalar, this.y*scalar, this.z*scalar);
	}
	
	public Vector3f add(Vector3f other){
		return new Vector3f(this.x+other.x, this.y+other.y, this.z+other.z);
	}

	public float dotProduct(Vector3f normal) {
		return (this.x * normal.x) + 
				(this.y * normal.y) + 
				(this.z * normal.z);
	}

	public Vector3f substract(Point3f p) {
		return new Vector3f(this.x - p.x, this.y - p.y, this.z - p.z);
	}
	
	public Vector3f normalize(){
		float length = this.length();
		return new Vector3f(this.x/length, this.y/length, this.z/length);
	}
}
